package com.qys.livesMall.shop.task;

import com.qys.livesMall.shop.service.ShopAutoReceivedService;
import com.qys.livesMall.shop.service.ShopAutoShippedService;
import io.netty.util.HashedWheelTimer;

import jakarta.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;

/**
 * @menu TaskProducer
 * @date 2023/07/05 17:29
 */
@Service
public class ShopTaskProducer implements ShopTaskInter{

    private static HashedWheelTimer timer=new HashedWheelTimer(1000, TimeUnit.MILLISECONDS, 256);

    @Resource @Lazy
    private ShopAutoShippedService shopAutoShippedService;
    @Resource @Lazy
    private ShopAutoReceivedService shopAutoReceivedService;


    public static void main(String[] args) {

    }

    @Override
    public void shippedTask(int times,Long orderId) {
        timer.newTimeout(timeout -> {
            shopAutoShippedService.exc(orderId);
        }, times, TimeUnit.SECONDS);
    }

    @Override
    public void receivedTask(int times, Long orderSkuId) {
        timer.newTimeout(timeout -> {
            shopAutoReceivedService.exc(orderSkuId);
        }, times, TimeUnit.SECONDS);
    }
}

